// 遍历;时间复杂度O(n);空间复杂度O(1)

class Solution {
public:
    vector<int> plusOne(vector<int>& digits) {
        int add = 1;
        int n = digits.size();
        for (int i = n - 1; i >= 0; i--) {
            digits[i] += add; 
            add = digits[i] / 10;
            digits[i] = digits[i] % 10;
        }
        if (add == 0) return digits;
        else {
            vector<int> ret(n + 1, 0);
            ret[0] = 1;
            return ret;
        } 
    }
};